package com.ruoyi.common.core.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.model.AmsAssetType;
import com.ruoyi.common.core.domain.model.AmsOwnAddress;
import com.ruoyi.common.core.text.Convert;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author yfkj
 */
@Data
@NoArgsConstructor
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    private Long key;

    /** 节点名称 */
    private String title;

    /** 资产数量 */
    private Integer assetNum;

    /** 资产金额 */
    private Integer assetAmount;

    private Long parentId;
    private String deptType;
    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect(AmsOwnAddress address)
    {
        this.key = address.getAddressId();
        this.title = address.getName();

        if (address.getChildren() != null){
            this.children = address.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }

    }
    public TreeSelect(AmsAssetType type)
    {
        this.key = type.getAssetTypeId();

        this.title = type.getAssetTypeName();

        if (type.getChildren() != null){
            this.children = type.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }

    }
    public TreeSelect(AmsAssetType type,Boolean isExcel)
    {
        this.key = type.getAssetTypeId();
        //this.title = type.getAssetTypeName();
        String[] strings = Convert.toStrArray(",", type.getAncestors());
        String name ="";
        for (String string : strings) {
            name=name +"  ";
        }
        name=name +type.getAssetTypeName();
        this.title =name;
        if (type.getChildren() != null){
            this.children = type.getChildren().stream().map(menuTree -> new TreeSelect(menuTree, false)).collect(Collectors.toList());
        }

    }
    public TreeSelect(SysDept dept)
    {
        this.key = dept.getDeptId();
        this.title = dept.getDeptShortName();
        this.parentId = dept.getParentId();
        this.deptType = dept.getDeptType();

        if (dept.getChildren() != null){
            this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }

    }

    public TreeSelect(SysMenu menu)
    {
        this.key = menu.getMenuId();
        this.title = menu.getName();

        if (menu.getChildren() != null){
            this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }

    }

    public TreeSelect(SysGeographical sysGeographical) {
        this.key = sysGeographical.getGeographicalId();
        this.title = sysGeographical.getGeographicalName();
        if (sysGeographical.getChildren() != null){
            this.children = sysGeographical.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
        }
    }

}
